package scuba.DiveBuddy.Core;

import android.content.Context;
import android.widget.Toast;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import scuba.DiveBuddy.Enums.DistanceEnum;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Alexander Anderson on 22/02/14.
 */
public class Toolbelt {
    public static final class Toolkit {

        public static DateTime getToday() {
            return new DateTime();
        }
        public static String getTodayAsString() {
            return getTodayAsString("dd/MM/yyyy");
        }
        public static String getTodayAsString(String format) {
            return getToday().toString(format);
        }

        public static String getDateAsString(LocalDate date) {
            return getDateAsString(date, "dd/MM/yyyy");
        }
        public static String getDateAsString(LocalDate date, String format) {
            return date.toString(format);
        }

        public static String getTimeAsString(LocalTime time) {
            return getTimeAsString(time, "HH:mm");
        }
        public static String getTimeAsString(LocalTime time, String format) {
            return time.toString(format);
        }

        public static LocalTime getTimeNow() {
            return new LocalTime();
        }

        public static LocalDate createDate(int year, int month, int day) {
            return new LocalDate(year, month, day);
        }
        public static LocalTime createTime(int hour, int min) {
            return createTime(hour, min, 0);
        }
        public static LocalTime createTime(int hour, int min, int second) {
            return new LocalTime(hour, min, second);
        }

        public static Tuple<Boolean, Float> getFloatFromString(String s, float d) {
            try {
                float v = Float.parseFloat(s);
                return new Tuple<Boolean, Float>(true, v);
            }
            catch(NumberFormatException nf) {
                return new Tuple<Boolean, Float>(false, d);
            }
        }
        public static String getDistanceExtension(DistanceEnum e) {
            switch(e) {

                case Feet: return "ft";
                case Metres: return "m";

                default:
                    return "";
            }
        }

        public static void showToast(Context ctx, String text) {
            Toast t = Toast.makeText(ctx, text, Toast.LENGTH_SHORT);
            t.show();
        }

    }


}
